package cn.com.reflect;

//        获取构造方法
//        Constructor<?>[] getConstructors()
//        Constructor<T> getConstructor(类<?>... parameterTypes)
//        Constructor<?>[] getDeclaredConstructors()
//        Constructor<T> getDeclaredConstructor(类<?>... parameterTypes)
//        获取成员方法
//        Method[] getMethods()
//        Method getMethod(String name, 类<?>... parameterTypes)
//        Method[] getDeclaredMethods()
//        Method getDeclaredMethod(String name, 类<?>... parameterTypes)
//        获取类名
//        getName()

import cn.com.domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        //获取Person的Class对象
        Class personClass = Person.class;
       //   Constructor<T> getConstructor(类<?>... parameterTypes)
        Constructor constructor = personClass.getConstructor(String.class, int.class);
        //创建对象
        Object person = constructor.newInstance("张三",23);

        System.out.println(person); //Person{name='张三', age=23, a='null', b='null', c='null', d='null'}
        System.out.println("--------------");

        Constructor constructor1 = personClass.getConstructor();
        //创建对象
        Object person1 = constructor1.newInstance();

        System.out.println(person1); //Person{name='null', age=0, a='null', b='null', c='null', d='null'}
        Object person2 = personClass.newInstance();
        System.out.println(person2); //Person{name='null', age=0, a='null', b='null', c='null', d='null'}
    }
}
